using System;
using System.Configuration;

namespace BIUtilities.Publish.CustomConfiguration
{
    /// <summary>
    /// Collection of PPS Excel Report Param elements
    /// </summary>
    public class PerformancePointExcelReportParamElementCollection :
        System.Configuration.ConfigurationElementCollection, IUpdatableConfig
    {

        /// <summary>
        /// Return a PPS Excel report param element by index
        /// </summary>
        /// <param name="index">Index of item</param>
        /// <returns></returns>
        public PerformancePointExcelReportParamElement this[int index]
        {
            get
            {
                return base.BaseGet(index) as PerformancePointExcelReportParamElement;
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        /// <summary>
        /// Create a new child element
        /// </summary>
        /// <returns></returns>
        protected override System.Configuration.ConfigurationElement CreateNewElement()
        {
            return new PerformancePointExcelReportParamElement();
        }

        /// <summary>
        /// Get the key of the child element
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((PerformancePointExcelReportParamElement)element).ParamName;
        }

        /// <summary>
        /// Makes this element editable
        /// </summary>
        /// <returns></returns>
        public override bool IsReadOnly()
        {
            return false;
        }


        #region IUpdatableConfig Members
        /// <summary>
        /// Creating a public accessor to get at the property values
        /// </summary>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        object IUpdatableConfig.this[string propertyName]
        {
            get { return base[propertyName]; }
            set { base[propertyName] = value; }
        }
        #endregion
    }
}
